package com.gidgabs.modules.api.controller.journal;

import com.gidgabs.common.annotation.LoginUserApi;
import com.gidgabs.common.utils.ReturnJson;
import com.gidgabs.common.validator.Assert;
import com.gidgabs.dto.TbUserDto;
import com.gidgabs.dto.TbUserJournalDto;
import com.gidgabs.modules.api.service.discovery.DiscoveryUserService;
import com.gidgabs.modules.api.service.journal.JournalJournalService;
import com.gidgabs.modules.entity.TbUser;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

/**
 * Created by tby on 2018/6/29.
 */
@Api("日志相关")
@RestController
@RequestMapping("api/journal")
public class ApiJournalController {

    @Autowired private JournalJournalService journalJournalService;


    @ApiOperation(value = "获取日志列表(按照点赞数,观看数量排序)")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "pageSize",value = "页面大小",dataType = "int",paramType = "query"),
            @ApiImplicitParam(name = "pageNo",value = "页码",dataType = "int",paramType = "query"),
            @ApiImplicitParam(name = "like",value = "模糊搜索",dataType = "string",paramType = "query"),
            @ApiImplicitParam(name = "token",value = "token",dataType = "string",paramType = "header")
    })
    @RequestMapping(value = "list", method = RequestMethod.GET, produces = {"application/json;charset=UTF-8"})
    public ReturnJson<TbUserJournalDto> queryList(Integer pageSize, Integer pageNo,String like ) {
        if (pageNo==null){
            pageNo=1;
        }if (pageSize==null)
            pageSize=10;

        return journalJournalService.queryList(pageSize,pageNo,like);
    }

    @ApiOperation(value = "获取日志详情")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "journalId",value = "日志id",dataType = "int",paramType = "path"),
            @ApiImplicitParam(name = "token",value = "token",dataType = "string",paramType = "header")
    })
    @RequestMapping(value = "{journalId}", method = RequestMethod.GET, produces = {"application/json;charset=UTF-8"})
    public ReturnJson<TbUserJournalDto> getById(@PathVariable Integer journalId ) {

        Assert.isNull(journalId,"journalId不能为空");
        return journalJournalService.getById(journalId);
    }

    @ApiOperation(value = "发表日志")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "videoId",value = "视频id",dataType = "string",paramType = "form"),
            @ApiImplicitParam(name = "fileName",value = "文件名称",dataType = "string",paramType = "form"),
            @ApiImplicitParam(name = "coverURL",value = "封面图片",dataType = "string",paramType = "form"),
            @ApiImplicitParam(name = "pictureUrl",value = "日志其他图片,多个图片用','隔开",dataType = "string",paramType = "form"),
            @ApiImplicitParam(name = "description",value = "日志文字内容",dataType = "string",paramType = "form"),
            @ApiImplicitParam(name = "title",value = "标题",dataType = "string",paramType = "form"),
            @ApiImplicitParam(name = "label",value = "标签",dataType = "string",paramType = "form"),
            @ApiImplicitParam(name = "rewardMoney",value = "打赏金额(分),无须打赏传0或者null",dataType = "int",paramType = "form"),
            @ApiImplicitParam(name = "rewardNum",value = "打赏人数",dataType = "int",paramType = "form"),
            @ApiImplicitParam(name = "token",value = "token",dataType = "string",paramType = "header")
    })
    @RequestMapping(value = "create", method = RequestMethod.POST, produces = {"application/json;charset=UTF-8"})
    public ReturnJson createJournal(  String videoId,String fileName,String coverURL,String pictureUrl,String description,String title,String label,Integer rewardMoney,Integer rewardNum ) {
        Assert.isNull(videoId,"videoId不能为空");
        return journalJournalService.createJournal(videoId,pictureUrl,description,fileName,coverURL,title,label,rewardMoney,rewardNum);
    }


    @ApiOperation(value = "日志点赞/取消点赞")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "journalId",value = "日志id",dataType = "int",paramType = "form"),
            @ApiImplicitParam(name = "token",value = "token",dataType = "string",paramType = "header")
    })
    @RequestMapping(value = "star", method = RequestMethod.POST, produces = {"application/json;charset=UTF-8"})
    public ReturnJson star(Integer journalId ) {
        Assert.isNull(journalId,"journalId不能为空");

        return journalJournalService.star(journalId);
    }



    @ApiOperation(value = "日志打赏")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "journalId",value = "日志id",dataType = "int",paramType = "form"),
            @ApiImplicitParam(name = "money",value = "打赏金额",dataType = "double",paramType = "form"),
            @ApiImplicitParam(name = "token",value = "token",dataType = "string",paramType = "header")
    })
    @RequestMapping(value = "reward", method = RequestMethod.GET, produces = {"application/json;charset=UTF-8"})
    public ReturnJson reward(Integer journalId,Double money) {
        Assert.isNull(journalId,"journalId不能为空");
        Assert.isNull(money,"money不能为空");
        return journalJournalService.reward(journalId,money);
    }

    @ApiOperation(value = "日志转载")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "journalId",value = "日志id",dataType = "int",paramType = "form"),
            @ApiImplicitParam(name = "money",value = "打赏金额",dataType = "double",paramType = "form"),
            @ApiImplicitParam(name = "token",value = "token",dataType = "string",paramType = "header")
    })
    @RequestMapping(value = "reprint", method = RequestMethod.GET, produces = {"application/json;charset=UTF-8"})
    public ReturnJson reprint(Integer journalId ) {
        Assert.isNull(journalId,"journalId不能为空");
        return journalJournalService.reprint(journalId);
    }

}
